﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Data;
using ProjectWebNhac.DAO;
using ProjectWebNhac.DTO;

namespace ProjectWebNhac.BUS
{
    public class AlbumBus
    {
        public AlbumBus() { }
        Dataprovider dao = new Dataprovider();
        TheLoaiBus theloaiBus = new TheLoaiBus();
        CaSiBus casiBus = new CaSiBus();
        DataTable dt;
        public DataTable LayDanhSachAlbum()
        {
            return dao.LayDuLieuThamSo("sp_Admin_LayAlbum", CommandType.StoredProcedure);
        }

        public bool UpdateLuotNgheAlbum(int MaAlbum)
        {
            object[] para = { "@MaAlbum", MaAlbum };
            bool kq = dao.XuLySuKien("sp_User_UpdateLuotNgheAlbum", CommandType.StoredProcedure, para);
            return kq;
        }

        public DataTable LayDanhSachAlbumTheoCaSi(int MaCaSi)
        {
            object[] para = { "@MaCaSi", MaCaSi };
            return dao.LayDuLieuThamSo("sp_Admin_LayAlbumTheoCaSi", CommandType.StoredProcedure,para);
        }

        public DataTable LayDanhSachAlbumTheoTheLoai(int MaTheLoai)
        {
            object[] para = { "@MaTheLoai", MaTheLoai };
            return dao.LayDuLieuThamSo("sp_User_LayAlbumTheoTheLoai", CommandType.StoredProcedure, para);
        }

       

        public DataTable LayDanhSachAlbumMoi()
        {
            return dao.LayDuLieuThamSo("sp_User_LayAlbumMoi", CommandType.StoredProcedure);
        }

        public DataTable LayDanhSachAlbumHot()
        {
            return dao.LayDuLieuThamSo("sp_User_LayAlbumHot", CommandType.StoredProcedure);
        }

        public DataTable LayChiTietAlbum(int MaAlbum)
        {
            object[] para = { "@MaAlbum", MaAlbum };
            return dao.LayDuLieuThamSo("sp_Admin_LayChiTietAlbum", CommandType.StoredProcedure, para);
        }

        public DataTable LaySoBaiHatTrongAlbum(int MaAlbum)
        {
            object[] para = { "@MaAlbum", MaAlbum };
            return dao.LayDuLieuThamSo("sp_User_LaySoBaiHatTrongAlbum", CommandType.StoredProcedure, para);
        }

        public bool ThemAlbum(AlbumDTO objAlbum)
        {
            int MaTheLoai = theloaiBus.LayMaTheLoaiTheoTen(objAlbum.TenTheLoai)[0];
            int MaCaSi = casiBus.LayMaCasiTheoTen(objAlbum.TenCasi)[0];
            return dao.XuLySuKien("sp_Admin_ThemAlbum", CommandType.StoredProcedure,
                new object[] { "@TenAlbum",objAlbum.TenAlbum,"@MaCaSi",MaCaSi,
                "@NgayPhatHanh",objAlbum.NgayPhatHanh,"@HinhAnh",objAlbum.HinhAnh,
                "@MaTheLoai",MaTheLoai });
        }

        public bool SuaAlbum(AlbumDTO objAlbum)
        {
            int MaTheLoai = theloaiBus.LayMaTheLoaiTheoTen(objAlbum.TenTheLoai)[0];
            int MaCaSi = casiBus.LayMaCasiTheoTen(objAlbum.TenCasi)[0];
            return dao.XuLySuKien("sp_Admin_SuaAlbum", CommandType.StoredProcedure,
                new object[] { "@MaAlbum",objAlbum.MaAlbum,"@TenAlbum",objAlbum.TenAlbum,
                "@MaCaSi",MaCaSi,"@NgayPhatHanh",objAlbum.NgayPhatHanh,"@HinhAnh",
                objAlbum.HinhAnh,"@MaTheLoai",MaTheLoai });
        }

        public bool XoaAlbum(int MaAlbum)
        {
            return dao.XuLySuKien("sp_Admin_XoaAlbum", CommandType.StoredProcedure,
                new object[] { "@MaAlbum", MaAlbum });
        }
        public bool KichHoatAlbum(int MaAlbum)
        {
            return dao.XuLySuKien("sp_Admin_KichHoatAlbum", 
           CommandType.StoredProcedure,new object[] { "@MaAlbum", MaAlbum });
        }
        public DataSet LayDanhSachAlbumPT(int currPage,
        int recodperpage,
        int Pagesize,
        int MaTheLoai)
        {
            return dao.LayDsThamSo("sp_User_PhanTrangAlbum", CommandType.StoredProcedure,
                new object[] { "@currPage", currPage, "@recodperpage", recodperpage, "Pagesize",
                    Pagesize,"@MaTheLoai",MaTheLoai });
        }

        public DataTable LayTop4DsAlBumTheoCaSi(int MaCaSi)
        {
            return dao.LayDuLieuThamSo("sp_User_LayAlbumTheoCaSi", CommandType.StoredProcedure,
                new object[] { "@MaCaSi", MaCaSi });
        }
        public DataTable LayTop3AlbumHotNhat()
        {
            return dao.LayDuLieuThamSo("sp_User_LayAlbumHotTrongTuan",
                CommandType.StoredProcedure);
        }
        public DataTable LayTop6AlbumMoiNhat()
        {
            return dao.LayDuLieuThamSo("sp_User_Lay6AlbumMoiNhat",
                CommandType.StoredProcedure);
        }
        public bool ThemBaiHatVaoAlbum(int MaAlbum,int MaBaiHat)
        {
            return dao.XuLySuKien("sp_Admin_ThemBaiHatVaoAlbum", CommandType.StoredProcedure,
                new object[] { "@MaAlbum",MaAlbum,"@MaBaiHat",MaBaiHat });
        }
        public DataSet TimKiemTheoTenAlbum(int currPage, int recodperpage, int Pagesize, string keyword)
        {
            return dao.LayDsThamSo("sp_User_TimKiemAlbum", CommandType.StoredProcedure,
                new object[] { "@currPage", currPage, "@recodperpage", recodperpage, "Pagesize",
                    Pagesize,"@txtSearch",keyword });
        }
    }
}